#include <cuda.h>
#include <cuda_runtime_api.h>
#include <vector_functions.h>

#ifdef	_DEBUG

#define	cudaSafeCall(err)	__cudaSafeCall(err, __FILE__, __LINE__)

static void __cudaSafeCall(cudaError err, const char *file, const int line )
{
	if (cudaSuccess != err)
	{
//		FPRINTF((stderr, "%s(%i) : cudaSafeCall() Runtime API error : %s.\n", file, line, cudaGetErrorString( err)));
		exit(-1);
	}
}

#else	// _DEBUG

#define	cudaSafeCall(err)	err

#endif	// _DEBUG


struct CudaImage
{
	unsigned int		width;
	unsigned int		height;
	unsigned int*		data;
};

struct CudaMaterial
{
	float3		diffuse;
	float3		specular;
	float		specularLevel;
	float		glossiness;
	float		reflectivity;
	float		transparency;
	float		refractionIndex;
	int			albedo;
	int			bump;
};

struct CudaSphere
{
	float3		center;
	float		radius;
	int			matID;
};

struct CudaBox
{
	float3		position;
	float3		Minimum;
	float3		Maximum;
	int			matID;
};

struct CudaPlane
{
	float3		normal;
	float		distance;
	float3		uAxis;
	float3		vAxis;
	int			matID;
};

struct CudaCamera
{
	float3		position;
	float3		direction;
	float3		U;
	float3		V;
};

struct CudaLight
{
	float3		position;
	float3		intensity;
};

__host__
void CudaRayTrace(unsigned int* imgData, unsigned int imgWidth, unsigned int imgHeight, const CudaSphere* spheres, int numSpheres,
				  const CudaBox* boxes, int numBoxes, const CudaPlane* planes, int numPlanes, const CudaMaterial* materials,
				  const CudaCamera* camera, const CudaLight* lights, int numLights);
__host__
void CudaInitTexture(const void* imageData, int width, int height, int texID);
__host__
void CudaFreeTexture(int texID);
